//
//  TabbarVC.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/2.
//  Copyright © 2019 李文强. All rights reserved.
//

#import "TabbarVC.h"
#import "MinButtonViewBtn.h"
#import "HomeViewController.h"
#import "SYHomeViewController.h"

#import "CoachViewController.h"
#import "JiaoYanViewController.h"
#import "ShiXunViewController.h"
#import "YueJuanViewController.h"
#import "ResourceViewController.h"
#import "TeacherVC.h"
#import "WoDeViewController.h"
#import "XiaoXiViewController.h"
#import "SYTuDiShiXunViewController.h"
#import "SYRequestAPI+HomePage.h"
#import "TheNewWorkListModel.h"
#import "RYChatBaseViewController.h"
#import "ChatTViewController.h"

@interface TabbarVC ()
@property (nonatomic, strong) NSMutableArray *tabbarArray;
@property (nonatomic, strong) NSMutableArray *imageArray;
@property (nonatomic, strong) NSMutableArray *imageSelectedArray;
@property (nonatomic, strong) UIImageView *header_imageView;
@property (nonatomic, strong) UIButton *clook_button;
@end

@implementation TabbarVC
- (NSMutableArray *)tabbarArray{
    if (!_tabbarArray) {
        NSMutableArray *array = [NSMutableArray new];
        _tabbarArray = array;
    }
    return _tabbarArray;
}
- (NSMutableArray *)imageArray{
    if (!_imageArray) {
        NSMutableArray *array = [NSMutableArray new];
        _imageArray = array;
    }
    return _imageArray;
}
- (NSMutableArray *)imageSelectedArray{
    if (!_imageSelectedArray) {
        NSMutableArray *array = [NSMutableArray new];
        _imageSelectedArray = array;
    }
    return _imageSelectedArray;
}
- (UIImageView *)header_imageView{
    if (!_header_imageView) {
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.layer.cornerRadius = 22.5;
        imageView.layer.masksToBounds = YES;
        imageView.image = [UIImage imageNamed:@"defalt_header"];
        imageView.userInteractionEnabled = YES;
        imageView.frame = CGRectMake(40-22.5,620.5,45,45);
        _header_imageView = imageView;
    }
    return _header_imageView;
}
- (UIButton *)clook_button{
    if (!_clook_button) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(40-15,688,30,25);
        [button setBackgroundImage:[UIImage imageNamed:@"clock"] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(clookClick:) forControlEvents:UIControlEventTouchUpInside];
        _clook_button = button;
    }
    return _clook_button;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)initSubView{
    [self.tabbarArray addObject:@"首页"];
    [self.tabbarArray addObject:@"教学"];
    [self.tabbarArray addObject:@"辅导"];
//    [self.tabbarArray addObject:@"教研"];
//    [self.tabbarArray addObject:@"师训"];
    [self.tabbarArray addObject:@"考评"];
    [self.tabbarArray addObject:@"资源"];
    [self.tabbarArray addObject:@"消息"];

    //RY_Massege_bar
    [self.imageArray addObject:@"homepage"];
    [self.imageArray addObject:@"teacheing"];
    [self.imageArray addObject:@"fu_dao"];
//    [self.imageArray addObject:@"jiao_yan"];
//    [self.imageArray addObject:@"shi_xun"];
    [self.imageArray addObject:@"yue_juan"];
    [self.imageArray addObject:@"resource"];
    [self.imageArray addObject:@"RY_Massege_bar"];

    [self goTeaching];
}
#pragma mark - 跳至Teaching
- (void)goTeaching{
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(getTeachingVC:) name:@"GoWorkListDetailNotification" object:nil];
    
}
- (void)getTeachingVC:(NSNotification *)info{
    TheNewWorkListModel *model = ( TheNewWorkListModel *)[info.userInfo objectForKey:@"model"];
    [self.delegate rootViewSwitch:5 andArray:self.tabArray andModel:model];
    for (int i = 0; i<self.tabArray.count-2; i++) {
        MinButtonViewBtn *bt = (MinButtonViewBtn *)[self.view viewWithTag:i+10];
        bt.selected = NO;
        if (i == 5) {
            bt.selected = YES;
        }
    }
}
- (void)initOption{
    for (int i = 0; i<_tabbarArray.count; i++) {
        CGFloat height = 70;
        CGFloat weight = TABBARITEMWIGHT;
        CGFloat y = i*height+44;
        CGRect rect = CGRectMake(0, y, weight, height);
        MinButtonViewBtn *button = [[MinButtonViewBtn alloc]initWithFrame:rect andType:ButtonImageInTop];
        button.bottomLabel.textColor = [UIColor whiteColor];
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:_tabbarArray[i] attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 13],NSForegroundColorAttributeName: [UIColorChange colorwithHexString:@"#FFFFFF"]}];
        button.bottomLabel.attributedText = string;
        button.tag = i+10;
        button.selected = NO;
        button.topImage.image = [UIImage imageNamed:self.imageArray[i]];
        [button addTarget:self action:@selector(changeVC:) forControlEvents:UIControlEventTouchUpInside];
        [button setBackgroundImage:[UIImage imageNamed:@"left_bar"] forState:UIControlStateSelected];
        [button setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor] forSize:CGSizeMake(60, 60)] forState:UIControlStateNormal];
        [self.view addSubview:button];
        if (i == 0) {
            button.selected = YES;
        }
    }
    //添加头像
    [self.view addSubview:self.header_imageView];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick)];
    [self.header_imageView addGestureRecognizer:tap];
    [_header_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(@620);
        make.width.equalTo(@45);
        make.height.equalTo(@45);
    }];
    
    [self.view addSubview:self.clook_button];
    [_clook_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(@688);
        make.width.equalTo(@30);
        make.height.equalTo(@30);
    }];
    //SYHomeViewController
//    HomeViewController *hvc = [[HomeViewController alloc]init];
//    TeacherVC *tea = [[TeacherVC alloc]init];
//    CoachViewController *co = [[CoachViewController alloc]init];
//    JiaoYanViewController *jiao_yan = [[JiaoYanViewController alloc]init];
//    SYTuDiShiXunViewController *jiao_yan = [[SYTuDiShiXunViewController alloc] init];//徒弟师训，先写上。上边的教研注销了。随后结束注销
    SYHomeViewController *hvc = [[SYHomeViewController alloc]init];
    TeacherVC *tea = [[TeacherVC alloc]init];
    CoachViewController *co = [[CoachViewController alloc]init];
//    JiaoYanViewController *jiao_yan = [[JiaoYanViewController alloc]init];
//    ShiXunViewController *shi_xun = [[ShiXunViewController alloc]init];
    YueJuanViewController *yue_juan = [[YueJuanViewController alloc]init];
    ResourceViewController *zi_yuan = [[ResourceViewController alloc]init];
    WoDeViewController *wo_de = [[WoDeViewController alloc]init];
    XiaoXiViewController *xiao_xi = [[XiaoXiViewController alloc]init];
    RYChatBaseViewController *RY_massge = [[RYChatBaseViewController alloc]init];
//    ChatTViewController *RY_massge = [[ChatTViewController alloc]init];

    [self.tabArray addObject:hvc];
    [self.tabArray addObject:tea];
    [self.tabArray addObject:co];
//    [self.tabArray addObject:jiao_yan];
//    [self.tabArray addObject:shi_xun];
    [self.tabArray addObject:yue_juan];
    [self.tabArray addObject:zi_yuan];
    [self.tabArray addObject:RY_massge];
    [self.tabArray addObject:wo_de];
    [self.tabArray addObject:xiao_xi];

    [self.delegate rootViewSwitch:0 andArray:self.tabArray];
    [self getJiaoSeCaiDan];
}
- (void)tapClick{
    //前往个人中心
    for (int i = 0; i<self.tabArray.count-2; i++) {
        MinButtonViewBtn *bt = (MinButtonViewBtn *)[self.view viewWithTag:i+10];
        bt.selected = NO;
    }
    [self.delegate rootViewSwitch:6 andArray:self.tabArray];
}

- (void)clookClick:(UIButton *)sender{
    //千万提示
    [self.delegate rootViewSwitch:7 andArray:self.tabArray];
    for (int i = 0; i<self.tabArray.count-2; i++) {
        MinButtonViewBtn *bt = (MinButtonViewBtn *)[self.view viewWithTag:i+10];
        bt.selected = NO;
    }
}
- (void)layout{
    
}
- (void)changeVC:(MinButtonViewBtn *)btn{
    for (int i = 0; i<self.tabArray.count-2; i++) {
        MinButtonViewBtn *bt = (MinButtonViewBtn *)[self.view viewWithTag:i+10];
        bt.selected = NO;
    }
    btn.selected = YES;
    int index = (int)btn.tag - 10;
    [self.delegate rootViewSwitch:index andArray:self.tabArray];
}
- (NSMutableArray *)tabArray{
    if (!_tabArray) {
        NSMutableArray *array = [[NSMutableArray alloc]init];
        _tabArray = array;
    }
    return _tabArray;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark - 获取角色菜单
- (void)getJiaoSeCaiDan{
    [SYRequestAPI sy_getRoleMenu:@{} success:^(id  _Nonnull responseObject) {
        NSLog(@"获取角色菜单成功 %@",responseObject);
    } fail:^(NSError *error) {
        
    }];
}
@end
